/*
 * 标题:          农务数据库检索系统
 * 
 * 描述:  		  以mysql为数据库，远程连接数据库进行水稻、 小麦、昆虫等数据库的检索
 * 
 * 备注:			 demo开头的html、jsp和java文件均为测试用例，无实际效用
 *
 * Copyright (c) 2017, Nanjing Agricultural University, China
 */

package cn.edu.njau.ads.view;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import cn.edu.njau.ads.control.demo_UserControl;
import cn.edu.njau.ads.model.demo_User;
import cn.edu.njau.ads.util.AppException;

/**
 * demo注册表单处理类
 * 
 * @author zzy
 *
 */
public class demo_RegisterAction extends ActionSupport{

	private static final long serialVersionUID = 1L;

	//声明并初始化用户信息服务层实现类
	private demo_UserControl userControl = new demo_UserControl();
		
		//获取form表单内容
		private HttpServletRequest req = ServletActionContext.getRequest();
		private String mobile = req.getParameter("mobile");
		private String name = req.getParameter("name");
		private String password = req.getParameter("password");
		
		/**
		 * 注册处理
		 */
		@Override
		public String execute(){
			//声明并初始化User对象，接受注册信息
			demo_User user = new demo_User();
			user.setName(name);
			user.setPassword(password);
			user.setMobile(mobile);
			
			try {
				//调用用户信息服务层处理注册请求，注册成功则跳转至登陆页
				if(userControl.register(user)){
					return "index";
				} else{//注册失败，则返回注册页面
					return "register";
				}
			} catch (AppException e) {
				e.printStackTrace();
				//系统异常，则跳转到404报错页面
				return "404";
			}
		}
}
